package com.xinou.daily_report.controller;

import com.xinou.common.base.config.ApiResponse;
import com.xinou.common.util.XoTreeUtil;
import com.xinou.daily_report.VO.DeptDTO;
import com.xinou.daily_report.VO.DeptVO;
import com.xinou.daily_report.mapper.SysDeptExpandMapper;
import com.xinou.sso.po.dept.DeptListPO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-06-11
 */
@RestController
@RequestMapping("/mini/dept/")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = {"前台部门"})
public class MiniDeptController {

    private final SysDeptExpandMapper sysDeptExpandMapper;

    @PostMapping("/list")
    @ApiOperation(value = "后台部门列表")
    @RequiresPermissions({"mini:dept:list"})
    public ApiResponse<DeptVO> deptList(@RequestBody DeptListPO po) {
        List<DeptDTO> vos = sysDeptExpandMapper.selectDeptList(po);
        return new ApiResponse<>(
                XoTreeUtil.covertTree(DeptVO.class, vos)
        );
    }

}

